import { Form, Input, InputNumber, Select } from 'antd';
import an58 from '@mmstudio/an000058';
import React, { useState } from 'react';
import { Message as M1, Result as R1 } from '../api/teamglz/add.api';
import AddButton from '../../components/addbutton';
import api from '../../atoms/api';



export default function Add({ teams, classs }: {
	teams: Pick<ITbteam, 'team_id' | 'teamname' | 'teammate'>[];
	classs: Pick<ITbclass, 'class_id' | 'classname' | 'grade'>[];
}) {
	const [d, setd] = useState({} as M1);
	return <>
		<AddButton dlgtitle='团队管理' onSave={async () => {
			if (!d
				|| !d.classname
				|| !d.teamname
				|| !d.grade
				|| !d.class_id
				|| !d.team_id
			) {
				return '缺少必要的参数';
			}
			const res = await an58<R1, M1>(api['/api/teamglz/add'], 'post', d);
			if (res.ok === true) {
				return true;
			}
			return res.message;
		}}>
			<Form.Item required label="年级:">
				<Select
					showSearch
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择年级'
					defaultValue={d.grade}
					onChange={(e) => {
						setd({
							...d,
							grade: e
						});
					}} >
					{classs.map((it) => {
						return <Select.Option key={it.grade} value={it.grade} >{it.grade}</Select.Option>;
					})}
				</Select>
			</Form.Item>
			<Form.Item required label="班级名称:">
				<Select
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择班级名称'
					value={d.class_id}
					onChange={(e) => {
						setd({
							...d,
							class_id: e
						});
					}} >
					{classs.map((it) => {
						return <Select.Option key={it.class_id} value={it.class_id} >{it.classname}</Select.Option>;
					})}
				</Select>
			</Form.Item>
			<Form.Item required label="团队名称">
				<Input placeholder='请输入团队名称' value={d.teamname} onChange={(e) => {
					setd({
						...d,
						teamname: e.target.value
					});
				}} />
			</Form.Item>
			<Form.Item required label="团队成员:">
				<Select
					showSearch
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择团队成员'
					defaultValue={d.teammate}
					onChange={(e) => {
						setd({
							...d,
							teammate: e
						});
					}} >
					{teams.map((it) => {
						return <Select.Option key={it.teammate} value={it.teammate} >{it.teammate}</Select.Option>;
					})}
				</Select>
			</Form.Item>
			<Form.Item required label="团队组长:">
				<Select
					showSearch
					optionFilterProp="children"
					filterOption={(input, option) => {
						return option.children.indexOf(input) >= 0;
					}}
					placeholder='请选择团队组长'
					defaultValue={d.teammate}
					onChange={(e) => {
						setd({
							...d,
							teammate: e
						});
					}} >
					{teams.map((it) => {
						return <Select.Option key={it.teammate} value={it.teammate} >{it.teammate}</Select.Option>;
					})}
				</Select>
			</Form.Item>
		</AddButton>
		<style jsx>{`
		.ta{
width:100%;
height:10rem;
}
.da{
width:100%;
height:10rem;
}
		`}</style>
	</>;
}
